import requests
import json

class HttpUtils:
    @staticmethod
    def http_post(headers, url, parameters):
        print("接口请求url：" + url)
        print("接口请求headers：" + json.dumps(headers))
        print("接口请求parameters：" + json.dumps(parameters))
        res = requests.request("POST",url, data=json.dumps(parameters), headers=headers,verify=False)
        print("接口返回结果："+res.text)
        if res.status_code != 200:
            raise Exception(u"请求异常")
        result = json.loads(res.text)
        return result

    @staticmethod
    def http_get(headers, url):
        req_headers = json.dumps(headers)
        print("接口请求url：" + url)
        print("接口请求headers：" + req_headers)
        res = requests.get(url, headers=headers,verify=False)
        print("接口返回结果：" + res.text)
        if res.status_code != 200:
            raise Exception(u"请求异常")
        result = json.loads(res.text)
        return result

if __name__ == '__main__':
    headers = {
          "Content-Type":"application/json"
      }
    url="http://180.76.36.251:9005/v2xapp/user/login"
    parameters=json.dumps({"username":"admin_123","password":"d6bf4bb9a66419380a7e8b034270d381","clientId":"frontend","grantType":"password"})
    test_request = HttpUtils()
    res = test_request.http_post(headers,url,parameters,)
    print(res)

